﻿@model IList<News>

@{
    ViewBag.Title = "Новости";
}
<style>
TD
{
	padding-left: 3em;
	padding-top: 1em
}
</style>
@if (ViewBag.isAdmin)
{
    <div class="lightbox" id="removeNewsBox">
    <a href="javascript:void(0)" class="lightbox_close">Закрыть</a>
    @using (Html.BeginForm("Delete", "News", FormMethod.Post))
    {
        <fieldset>
            @Html.Hidden("Id", "", new { id = "removeBoxNewsId" })
        </fieldset>
        <p>
            Вы уверены, что хотите удалить новость <br/>'<span id="removeBoxNewsTitle"></span>'?</p>
	 
        @Html.SubmitButton(null, "Удалить")
    }
</div>
    <script type="text/javascript">
        $(function () {
            $(".removeNews").click(function () {
                $("#removeBoxNewsId").val($(this).attr("newsId"));
                $("#removeBoxNewsTitle").text($(this).attr("newsTitle"));
            }
         );
        });
    </script> 
}
@if (!Model.Any())
{
	<div>
		Нет новостей
	</div>
}
else
{  
	<table>
	<tbody>
	@foreach (var n in Model)
 {
		<tr>
            @if (ViewBag.isAdmin)
            {
            <td>
			    <form action="@Url.Action("ShowHide")" class="ajaxForm" method="post">
                    <input type="hidden" name="Id" value="@n.Id"/>
                    <input type="submit" value="@(n.IsHidden ? "Показывать" : "Скрыть")" />
                </form>
                <a href="javascript:void(0)" class="showLightBox_link removeNews asButton asButton_container" 
                    title="удалить" rel="removeProjectBox" 
                    newsId="@n.Id" newsTitle="@n.Title">удалить</a>
			</td>
            }
			<td>
				<ul class="newsListItem">
					<li>
						<div class="newListTitleContainer">@(Html.ActionLink<NewsController>(x => x.View(n.Id), n.Title, new {@class="newsListItemTitle"}))</div>
					</li>
					<li>
						<div class="newListShortContentContainer">@(Html.ActionLink<NewsController>(x => x.View(n.Id), n.ShortContent, new { @class = "newsListItemShortContent" }))</div>
					</li>
					<li>
						<div class="newsDateCreated">Добавлена: @n.DateCreated.ToString("dd MMMM yyyy")</div>
					</li>
				</ul>
			</td>
            <td>@NewsAvatar.Small(n, imageClass: "news_photo")</td>
			<td>
            @if (n.IsHidden)
            {
				<span class="warning">новость скрыта</span><br/>
            }
			
			</td>
            
		</tr>
 }
	</tbody>
	</table>
}